package com.my.chapter21;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class practice20 {
    public static void main(String[] args) {
        ExecutorService exec = Executors.newCachedThreadPool();
        for(int i = 0; i < 5; i++)
            exec.execute(new LiftOff3());
        Thread.yield();
        exec.shutdownNow();
    }
}

class LiftOff3 implements Runnable {
    protected int countDown = 5000;
    private static int taskCount;
    private final int id = taskCount++;
    public LiftOff3() {}
    public LiftOff3(int countDown) {
        this.countDown = countDown;
    }
    public String status() {
        return "#" + id + "(" +
                (countDown > 0 ? countDown : "Liftoff!") + "), ";
    }
    public void run() {
        while(countDown-- > 0) {
            if(Thread.currentThread().isInterrupted()) {
                System.out.println("Interrupted: #" + id);
                return;
            }
            System.out.print(status());
            Thread.yield();
        }
    }
}
